package com.java.admin.serviceType.controller;

import com.github.pagehelper.PageInfo;
import com.java.admin.serviceType.entity.AddEntity;
import com.java.database.entity.Servicetype;
import com.java.admin.serviceType.service.ServeService;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@ResponseBody
public class ServiceTypeController {
    @Autowired
    private ServeService serveService;
    @RequestMapping(value = "/addServiceType",produces="text/html;charset=UTF-8;")
    public String add(Servicetype servicetype) {
        int add = serveService.add(servicetype);
        //redirect:/admin/addservetype.html
        if(add==1){
            return "添加成功";
        }
       return "添加失败";
    }
    @RequestMapping("/queryServiceType")
    public PageInfo query(String pageNum,String condition){
        Logger logger = LogManager.getLogger(ServiceTypeController.class);
        logger.debug("记录1");
        PageInfo pageInfo = serveService.queryAll(pageNum, condition);
        return pageInfo;
    }
    @RequestMapping("/queryServiceTypeById")
    public Servicetype queryServeById(String servicetypeid){
        Servicetype servicetype = serveService.queryServeById(servicetypeid);
        return servicetype;
    }
    @RequestMapping(value = "/removeServiceType",produces="text/html;charset=UTF-8;")
    public String remove(String servicetypeid) {
        int remove = serveService.remove(servicetypeid);
        if(remove==1){
            return "删除成功";
        }
        return "删除失败";
    }
    @RequestMapping(value = "/updateServiceType",produces="text/html;charset=UTF-8;")
    public String update(Servicetype servicetype) {
        int update = serveService.update(servicetype);
        if(update==1){
            return "修改成功";
        }
        return "修改失败";
    }


    /**
     *  添加服务类型
     * @param addEntity-------------
     */
    @RequestMapping("/addServiceType")
    public String addServiceType(@ModelAttribute  AddEntity addEntity){
        addEntity.change();
        serveService.addServiceType(addEntity);

        return "serviceType.html";
    }
}
